home *** CD-ROM | disk | FTP | other *** search
- TABLE OF CONTENTS
- 0001 SmartReadArgs/--background--
- 0002 SmartReadArgs/--history--
- 0003 SmartReadArgs/SmartFreeArgs
- 0004 SmartReadArgs/SmartReadArgs
- SmartReadArgs/--background--
-
- COPYRIGHT
- SmartReadArgs is Copyright 1998 Thomas Aglassinger
-
- ExtReadArgs, its prequel, is Copyright 1994,1995 Stefan Ruppert
-
- Permission is granted to freely distribute the material (also only
- parts of it) as long this ReadMe is included and all the copyright
- notes are left unaltered except for a description of your changes.
-
- MOTIVATION
- The way of parsing ToolTypes provided by "icon.library" is rather
- clumsy. This is particular annoying as many programmers and users got
- used to ReadArgs(), which does the argument handling for many CLI
- commands and ARexx ports.
-
- Unfortunately, ReadArgs lacks a interface to Workbench tooltypes, thus
- its usage preventes your programs from being started from Workbench.
-
- SmartReadArgs() copies all Workbench arguments in a single string and
- passes this string to the ReadArgs() function. If started from CLI, it
- calls ReadArgs() without this step.
-
- AUTHOR
- Stefan Ruppert wrote most parts of the source code, designed the general
- interface and implemented loads of nice features. Basically he did the
- "hard work".
-
- He got the main idea for the implementation from Stefan Winterstein,
- the author of ARoach.
-
- Thomas Aglassinger <agi@sbox.tu-graz.ac.at> did some minor changes,
- established a more consistent naming schema, reworked the documentation
- and also added support for gcc/libnix.
-
- Contact him in case of problems or if you made some enhancements.
-
- Updates are available from aminet:dev/misc/SmartReadArgs.lha.
-
- DISCLAIMER
- There is no warranty for this software package. Although the author
- has tried to prevent errors, he can't guarantee that the software
- package described in this document is 100% reliable. You are
- therefore using this material at your own risk. The author cannot be
- made responsible for any damage which is caused by using this
- software package.
-
- SmartReadArgs/--history--
-
- HISTORY
- Version 1.6, 7-Sep-1998
-
- - Changed name to SmartReadArgs to avoid confusion with other work based
- on the same material
- - Changed function parameters for SmartReadArgs() so that no more SAS/c
- specific values of argc/argv are required (Of course it still works
- with SAS/c, but you have to provide the WBStartup from "outside").
- - Changed all #include <clib/...> to #include <proto/..>, except for
- <clib/alib_stdio_protos.h> in "test.c". Where the hell is this one?
- - Added feature to ignore tooltypes that are not in the template
- - Added some missing includes in SmartReadArgs.c so the source codes
- compile without warnings
- - Changed #include <debug.h> to #include "debug.h" and provided a proper
- debug.h
- - The WINDOW tooltype is handled properly even if it is not entirely
- written in upper case.
- - Requires "utility.library" to be open as Stricmp() is used several
- times
- - Changed from Printf() to printf() using stdio of amiga.lib to make the
- code compile easier on non-SAS environments
- - Changed autodoc tool to Robodoc
- - Fixed enforcer hit if no tooltypes were provided at all
- - Remove some "char filename[34]" stuff and replaced the array dimension
- by MAXIMUM_FILENAME_LENGTH for future compatibility
- - Cleaned-up autodocs
-
- ANCIENT HISTORY
- ExtReadArgs() by Stefan Ruppert
-
- See aminet:dev/misc/extrdargs_v1.5.lha for the original version.
-
- $HISTORY
- 08.01.95 : 001.005 : changed to ExtReadArgs()
- 24.09.94 : 001.004 : now checks after ReadArgs the SIGBREAKF_CTRL_C
- flag, thus if anyone canceled during ReadArgs()
- help ExtReadArgs() fails
- 08.09.94 : 001.003 : between two switches (no equal sign) there was
- no space, this is fixed
- 08.09.94 : 001.002 : wb files now enclosed in quotes
- 04.09.94 : 001.001 : bumped to version 1
- 19.05.94 : 000.001 : initial
-
- SmartReadArgs/SmartFreeArgs
-
- NAME
- SmartFreeArgs -- Free all resources allocated by SmartReadArgs().
-
- SYNOPSIS
- SmartFreeArgs(smart_args);
-
- void SmartFreeArgs(struct SmartArgs *);
-
- FUNCTION
- Free all resources allocated by a previous call to SmartReadArgs().
-
- INPUTS
- smart_args - Same pointer as passed to SmartReadArgs() before
-
- NOTES
- Always call SmartFreeArgs(), even if SmartReadArgs() failed! Take a look
- at the example for SmartReadArgs().
-
- SEE ALSO
- SmartReadArgs()
-
- SmartReadArgs/SmartReadArgs
-
- NAME
- SmartReadArgs -- Workbench/CLI transparent ReadArgs().
-
- SYNOPSIS
- error = SmartReadArgs(wb_startup, smart_args);
-
- LONG SmartReadArgs(struct WBStartup *, struct SmartArgs *);
-
- FUNCTION
- This function is a CLI/Workbench transparent interface to ReadArgs().
-
- In case of a Workbench start, it analyzes the WBStartup message and
- possible tooltypes. These are converted to a text string that can be
- passed to ReadArgs() like before.
-
- Tooltypes that are not part of the template are ignored. This includes
- tooltypes being disabled with "(...)", NewIcons image data on systems
- without NewIcons installed and all this «« Icon by some idiot »» crap.
-
- If the application was stared from CLI, it simply calls ReadArgs()
- without the conversion step.
-
- If all went well you get a return value of zero. This means the passed
- arguments fit the template and are ready to use. Otherwise you get a
- IoErr()-like return code.
-
- INPUTS
- wb_startup - Workbench startup message. Refer to your compiler manual
- to learn how to obtain it. If this is NULL, the program was
- started from CLI.
- smart_args - structure which holds all information used by
- SmartReadArgs(). You have to setup the following fields before the
- call:
-
- sa_Template - The template passed to ReadArgs()
- sa_Parameter - ReadArgs() LONG WORD array to hold the arguments
- sa_FileParameter - number of Argument in the template to use
- for the files passed via WBStartup->sm_ArgList or -1, that
- means you don't want any files
- sa_Window - Window description string to open when the program
- is started from the workbench. NULL means no window. If the
- icon has a WINDOW tooltype, this value is ignored.
- sa_RDArgs - RDArgs structure to use for ReadArgs() call. This
- can be used to provide extended help.
- sa_Buffer - Pointer to a buffer to use for the Workbench startup
- or NULL, that means SmartReadArgs() allocates a buffer for you
- sa_BufferSize - Size of the optional buffer. If it is smaller than
- SA_MINIMUM_BUFFER_SIZE it will be adjusted.
-
- All other fields should be set to NULL.
-
- RESULT
- Zero for success. You can check the sa_Flags field for the
- SAF_WORKBENCH flag to learn how the program was started.
-
- Otherwise an IoErr()-like error code is returned. This can be passed
- directly to PrintFault() or similar.
-
- NOTES
- Always call SmartFreeArgs(), even if SmartReadArgs() failed! See example
- below.
-
- This function requires "dos.library", "icon.library" and
- "utility.library" to be opened by the application. Normally this
- already has been done by the compiler startup code.
-
- There is a not widely known feature of ReadArgs(): with templates like
- "FROM/M/A,TO/A", you can select the files from workbench performing the
- following steps:
-
- - Select the program
- - Select the FROM files
- - Select and double click the TO file
-
- This is available because ReadArgs() grabs the last string from a
- multi-argument FROM and uses it as the TO parameter, if none is passed
- explicitely.
-
- BUGS
- There are some known problems when used with GCC, mostly related to the
- fact that I never bothered creating a useable developer environment
- around it (and I'm not sure if this is even possible >:) ...):
-
- - Debugging output shows up in the console instead of SER:. Does
- debug.lib exist for gcc? (Wasn't there this strange hunk2gcc
- converter?)
- - "Read from 0" Enforcer hit in SmartReadArgs(). Couldn't figure out
- the exact location yet because of the asynchronous debugging output
- mentioned above.
-
- For someone with a reasonable experience with GCC, it should be easy to
- fix this.
-
- The SAS/c implementation does not have these problems.
-
- SEE ALSO
- SmartFreeArgs(), dos.library/ReadArgs(), icon.library/GetDiskObjectNew()
-
- EXAMPLE
- The main archiev comes with a "test.c" and a couple of icons to start
- the corresponding executable "test". Take a look at the source code and
- play with it.
-
- See below for a smaller code segment that expects the "dos.library",
- "icon.library" and "utility.library" to be open already.
-
- SOURCE
- int main(int argc, STRPTR argv[])
- {
- struct SmartArgs smart_args =
- {NULL};
- LONG argument[2];
- LONG error;
-
- /* Obtain WBStartup; depends on your compiler environment */
- struct WBStartup *wb_startup = NULL;
- #ifdef __GNUC__
- wb_startup = _WBenchMsg;
- #else
- if (argc == 0)
- {
- wb_startup = (struct WBStartup *) argv;
- }
- #endif
-
- smart_args.sa_Template = "FILES/M/A,VERBOSE";
- smart_args.sa_Parameter = argument;
- smart_args.sa_FileParameter = 0;
- smart_args.sa_Window = "CON:////My WB-Window/AUTO/CLOSE/WAIT";
-
- error = SmartReadArgs(wb_startup, &smart_args);
- if (error == 0)
- {
- /* do something */
- }
- else
- {
- PrintFault(error, "MyProgram");
- }
-
- SmartFreeArgs(&smart_args);
-
- return ((error == 0) ? RETURN_OK : RETURN_FAIL);
- }
-